<?php 
 session_start(); 
 date_default_timezone_set('Asia/Ho_Chi_Minh');
include_once("../DataProvider.php");
if(isset($_SESSION["listGame"]) && !empty($_SESSION["listGame"]))
{
$username = $_POST["username"];

$phone = $_POST["phone"];

$sql ="insert into tbl_bills(UserName,Phone,CreateDate) values('$username','$phone','".date('Y-m-d')."')";

	$idBill = DataProvider::ExecuteQueryGetID($sql);
	
	foreach($_SESSION["listGame"] as $value)
	{
		$sql1="insert into tbl_detailbill(IDBill,IDGame) values($idBill,$value); ";
		DataProvider::ExecuteQuery($sql1);
		$sql1="update tbl_games set Downloaded = Downloaded + 1 where GameID = $value";
		DataProvider::ExecuteQuery($sql1);
	}
	$_SESSION["idBill"] = $idBill;
	$_SESSION["listGame"]=array();

	$_SESSION["countGame"]=0;

	$_SESSION["totalSize"]=0;

	$_SESSION["totalPrice"]=0;
	}
	header("Location: ../xemhoadon.php");//?id=".$idBill);

?>
